<?php

namespace app\home\controller\user;

use app\home\controller\AuthController;
use think\facade\Db;
use app\home\model\user\{UserCar, User};
use services\{JsonService as Json, UtilService as Util};
use think\Facade\Route as Url;


/**
 * 会员的车辆管理部分
 * Class CarList
 * @package app\home\controller\user
 */
class CarList extends AuthController
{
    /**
     * 首页
     * @return string
     */
    public function index()
    {
        // 获取所有的会员
        $user_list = User::where("wxapp_id", $this->wxapp_id)->field("uid, nickname, account")->order("uid DESC")->select();
        $this->assign(compact("user_list"));
        return $this->fetch();
    }

    /**
     * 获取车辆的列表
     */
    public function get_car_list()
    {
        $where = Util::getMore([
            ["page", 1],
            ["limit", 20],
            ["nickname", ''],
            ["license_no", ""],
            ["recent_time", ""],
            ["user_time_type", ""]
        ], $this->request);
        return Json::successlayui(UserCar::getAllCar($where));
    }

    /**
     * 删除
     * @return false|string
     * @throws \think\db\exception\DbException
     */
    public function del_car()
    {
        $id = $this->request->param("id");
        if (Db::name("user_car")->where("id", $id)->update(["is_del" => 1])) {
            return Json::successful("删除成功");
        }
        return Json::fail("删除失败");
    }
}